package com.huawei.appmarket.support.audio;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import huawei.widget.HwSeekBar;
import huawei.widget.HwSeekBar.a;
import java.lang.ref.WeakReference;
import java.util.Formatter;
import java.util.Locale;
import o.cks;
import o.cku;
import o.dky;
import o.dky.h;
import o.dky.i;
import o.dky.j;
import o.doo;
import o.epd;
import o.epe;
import o.eph;
import o.epm;
import o.NetWorkUtil;

public class AudioPlayerView extends LinearLayout implements OnClickListener {
    private TextView ʻ;
    private TextView ʼ;
    private TextView ʽ;
    private HwSeekBar ˊ;
    private final Formatter ˋ;
    private epd ˋॱ;
    private View ˎ;
    private final StringBuilder ˏ;
    private String ͺ;
    private ImageView ॱ;
    private AudioBean ॱॱ;
    private boolean ᐝ;

    class b implements a {
        final /* synthetic */ AudioPlayerView ˎ;

        b(AudioPlayerView audioPlayerView) {
            this.ˎ = audioPlayerView;
        }

        public void ˎ(HwSeekBar hwSeekBar, int i, boolean z) {
            if (hwSeekBar.isPressed()) {
                epe.ˏ().ˋ(this.ˎ.ॱॱ, hwSeekBar.getProgress(), false);
                this.ˎ.ʽ();
            }
        }

        public void ˎ(HwSeekBar hwSeekBar) {
        }

        public void ॱ(HwSeekBar hwSeekBar) {
            epe.ˏ().ˋ(this.ˎ.ॱॱ, hwSeekBar.getProgress(), true);
            this.ˎ.ʽ();
        }
    }

    static class c implements epd {
        private WeakReference<AudioPlayerView> ॱ;

        public c(AudioPlayerView audioPlayerView) {
            this.ॱ = new WeakReference(audioPlayerView);
        }

        public void ˊ(AudioBean audioBean) {
            AudioPlayerView audioPlayerView = (AudioPlayerView) this.ॱ.get();
            if (audioPlayerView != null && audioBean != null) {
                if (audioBean.equals(audioPlayerView.ॱॱ)) {
                    audioPlayerView.ᐝ = true;
                } else {
                    audioPlayerView.ᐝ = false;
                }
                audioPlayerView.setImg();
                cku.ˎ(audioPlayerView.getContext(), "audio.clickStartPlay");
            }
        }

        public void ˊ(int i) {
            AudioPlayerView audioPlayerView = (AudioPlayerView) this.ॱ.get();
            if (audioPlayerView != null && audioPlayerView.ᐝ && audioPlayerView.ॱॱ != null) {
                audioPlayerView.ॱॱ();
                audioPlayerView.ʽ();
                audioPlayerView.ʼ();
                audioPlayerView.setImg();
            }
        }

        public void ॱ(int i, int i2) {
            AudioPlayerView audioPlayerView = (AudioPlayerView) this.ॱ.get();
            if (audioPlayerView != null && audioPlayerView.ᐝ) {
                audioPlayerView.ʽ();
                if (!audioPlayerView.ˊ.isPressed() && i2 > 0) {
                    audioPlayerView.ˊ.setProgress(i);
                }
            }
        }

        public void ˎ() {
            AudioPlayerView audioPlayerView = (AudioPlayerView) this.ॱ.get();
            if (audioPlayerView != null && audioPlayerView.ᐝ) {
                audioPlayerView.setImg();
            }
        }

        public void ˋ(int i) {
            AudioPlayerView audioPlayerView = (AudioPlayerView) this.ॱ.get();
            if (audioPlayerView != null && audioPlayerView.ᐝ) {
                audioPlayerView.ˊ.setSecondaryProgress((int) ((((float) i) / 100.0f) * ((float) audioPlayerView.ˊ.getMax())));
            }
        }

        public void ˋ() {
            AudioPlayerView audioPlayerView = (AudioPlayerView) this.ॱ.get();
            if (audioPlayerView != null && audioPlayerView.ᐝ) {
                audioPlayerView.setImg();
            }
        }

        public void ˋ(int i, String str) {
            AudioPlayerView audioPlayerView = (AudioPlayerView) this.ॱ.get();
            if (audioPlayerView != null && audioPlayerView.ᐝ) {
                audioPlayerView.setImg();
            }
        }
    }

    public AudioPlayerView(Context context) {
        this(context, null);
    }

    public AudioPlayerView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public AudioPlayerView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        ˋ();
        this.ˋॱ = new c(this);
        this.ˏ = new StringBuilder();
        this.ˋ = new Formatter(this.ˏ, Locale.getDefault());
    }

    private void ˋ() {
        this.ˎ = LayoutInflater.from(getContext()).inflate(i.ॱॱ, this);
        this.ॱ = (ImageView) this.ˎ.findViewById(h.ˍ);
        this.ˊ = (HwSeekBar) this.ˎ.findViewById(h.ˋˋ);
        this.ʻ = (TextView) this.ˎ.findViewById(h.ˎˎ);
        this.ʽ = (TextView) this.ˎ.findViewById(h.ˏˎ);
        this.ʼ = (TextView) this.ˎ.findViewById(h.ˊ);
        this.ॱ.setOnClickListener(this);
        this.ˊ.setOnSeekBarChangeListener(new b(this));
    }

    public void setData(AudioBean audioBean) {
        this.ॱॱ = audioBean;
        setTag(this.ॱॱ);
    }

    public void ˊ() {
        ʻ();
        ʼ();
        ॱॱ();
        ʽ();
        setImg();
        setPlayCallback();
        if (epe.ˏ().ॱ(this.ॱॱ)) {
            this.ᐝ = true;
        } else {
            this.ᐝ = false;
        }
    }

    public void setImg() {
        if (this.ॱॱ == null || this.ॱॱ.ʽ() != 1) {
            this.ॱ.setImageResource(dky.a.ˊ);
        } else {
            this.ॱ.setImageResource(dky.a.ˎ);
        }
    }

    private void ʽ() {
        if (this.ʻ != null && this.ॱॱ != null) {
            this.ʻ.setText(epm.ˏ(this.ˏ, this.ˋ, (long) this.ॱॱ.ʼ()));
        }
    }

    private void ॱॱ() {
        if (this.ʽ != null && this.ॱॱ != null) {
            this.ʽ.setText(epm.ˏ(this.ˏ, this.ˋ, (long) this.ॱॱ.ᐝ()));
        }
    }

    private void ʻ() {
        if (this.ʼ != null && this.ॱॱ != null) {
            this.ʼ.setText(this.ॱॱ.ॱ());
        }
    }

    private void ʼ() {
        if (this.ॱॱ != null && this.ˊ != null) {
            this.ˊ.setMax(this.ॱॱ.ᐝ());
            this.ˊ.setProgress(this.ॱॱ.ʼ());
            this.ˊ.setSecondaryProgress((int) ((((float) this.ॱॱ.ˊॱ()) / 100.0f) * ((float) this.ॱॱ.ᐝ())));
        }
    }

    private boolean ᐝ() {
        Context context = getContext();
        if (!doo.ͺ(context) || !epe.ˏ().ॱॱ()) {
            return true;
        }
        if (cku.ˏ(context, "audio.clickStartPlay")) {
            return false;
        }
        cku ˏ = cku.ˏ(context, cku.class, null, NetWorkUtil.getWifiResId(context, j.ˋॱ));
        ˏ.ॱ(new cks(this) {
            final /* synthetic */ AudioPlayerView ˎ;

            {
                this.ˎ = r1;
            }

            public void enableNetworking() {
                epe.ˏ().ˎ(false);
                this.ˎ.ॱ();
                this.ˎ.setImg();
            }

            public void upgrade() {
            }

            public void ˋ() {
            }
        });
        ˏ.ˋ(context, "audio.clickStartPlay");
        return false;
    }

    public void onClick(View view) {
        if (this.ॱॱ != null) {
            if (this.ॱॱ.ʽ() == 1) {
                epe.ˏ().ʽ(4);
                epe.ˏ().ˋ(this.ॱॱ);
            } else if (ᐝ()) {
                epe.ˏ().ͺ();
                ॱ();
            } else if (!epe.ˏ().ॱ(this.ॱॱ)) {
                epe.ˏ().ˊ(0);
            }
            setImg();
        }
    }

    public void ॱ() {
        String ˎ = ˎ();
        if (this.ॱॱ != null) {
            this.ॱॱ.ˎ(ˎ);
            setPlayCallback();
            if (ˏ(this.ॱॱ.ˏ())) {
                epe.ˏ().ˏ(this.ॱॱ);
            }
            this.ॱॱ.ˊ(0);
            epe.ˏ().ʽ(0);
            boolean ʻ = epe.ˏ().ʻ();
            boolean ˋ = epe.ˏ().ˋ(this.ॱॱ.ॱॱ(), this.ॱॱ.ˏ());
            if (ʻ && !ˋ) {
                epe.ˏ().ॱˊ();
            }
            epe.ˏ().ˊ(this.ॱॱ);
        }
    }

    public void setPlayCallback() {
        epe.ˏ().ˋ(this.ˋॱ);
    }

    public void onStartTemporaryDetach() {
        super.onStartTemporaryDetach();
        epe.ˏ().ˊ(this.ˋॱ);
    }

    public String ˎ() {
        if (this.ͺ == null) {
            eph ˏ = ˏ();
            if (ˏ != null) {
                this.ͺ = ˏ.ॱʾ();
            }
        }
        return this.ͺ;
    }

    public eph ˏ() {
        Context context = getContext();
        if (context != null && (context instanceof FragmentActivity)) {
            for (Fragment fragment : ((FragmentActivity) context).ˏॱ().ˏ()) {
                if ((fragment instanceof eph) && ˏ(fragment)) {
                    return (eph) fragment;
                }
            }
        }
        return null;
    }

    public boolean ˏ(Fragment fragment) {
        return ˎ(fragment.getView());
    }

    public boolean ˎ(View view) {
        for (Object parent = getParent(); parent != null; parent = parent.getParent()) {
            if (parent == view) {
                return true;
            }
        }
        return false;
    }

    private boolean ˏ(String str) {
        if (str != null) {
            return str.startsWith("widesubstancedetail|");
        }
        return false;
    }
}
